/* The link = http://poj.org/problem?id=1051
 * The problem is a paper tiger
 */

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>

using namespace std;

// Store the maps
map<string, string> encryption, decryption;


int main(int argc, char *argv[])
{
	encryption.insert(pair<string, string>("A", ".-"));    decryption.insert(pair<string, string>(".-", "A"));
	encryption.insert(pair<string, string>("B", "-..."));  decryption.insert(pair<string, string>("-...", "B"));
	encryption.insert(pair<string, string>("C", "-.-."));  decryption.insert(pair<string, string>("-.-.", "C"));
	encryption.insert(pair<string, string>("D", "-.."));   decryption.insert(pair<string, string>("-..", "D"));
	encryption.insert(pair<string, string>("E", "."));     decryption.insert(pair<string, string>(".", "E"));
	encryption.insert(pair<string, string>("F", "..-."));  decryption.insert(pair<string, string>("..-.", "F"));
	encryption.insert(pair<string, string>("G", "--."));   decryption.insert(pair<string, string>("--.", "G"));
	encryption.insert(pair<string, string>("H", "...."));  decryption.insert(pair<string, string>("....", "H"));
	encryption.insert(pair<string, string>("I", ".."));    decryption.insert(pair<string, string>("..", "I"));
	encryption.insert(pair<string, string>("J", ".---"));  decryption.insert(pair<string, string>(".---", "J"));
	encryption.insert(pair<string, string>("K", "-.-"));   decryption.insert(pair<string, string>("-.-", "K"));
	encryption.insert(pair<string, string>("L", ".-.."));  decryption.insert(pair<string, string>(".-..", "L"));
	encryption.insert(pair<string, string>("M", "--"));    decryption.insert(pair<string, string>("--", "M"));
	encryption.insert(pair<string, string>("N", "-."));    decryption.insert(pair<string, string>("-.", "N"));
	encryption.insert(pair<string, string>("O", "---"));  decryption.insert(pair<string, string>("---", "O"));
	encryption.insert(pair<string, string>("P", ".--."));    decryption.insert(pair<string, string>(".--.", "P"));
	encryption.insert(pair<string, string>("Q", "--.-"));  decryption.insert(pair<string, string>("--.-", "Q"));
	encryption.insert(pair<string, string>("R", ".-."));   decryption.insert(pair<string, string>(".-.", "R"));
	encryption.insert(pair<string, string>("S", "..."));  decryption.insert(pair<string, string>("...", "S"));
	encryption.insert(pair<string, string>("T", "-"));    decryption.insert(pair<string, string>("-", "T"));
	encryption.insert(pair<string, string>("U", "..-"));    decryption.insert(pair<string, string>("..-", "U"));
	encryption.insert(pair<string, string>("V", "...-"));  decryption.insert(pair<string, string>("...-", "V"));
	encryption.insert(pair<string, string>("W", ".--"));   decryption.insert(pair<string, string>(".--", "W"));
	encryption.insert(pair<string, string>("X", "-..-"));  decryption.insert(pair<string, string>("-..-", "X"));
	encryption.insert(pair<string, string>("Y", "-.--"));    decryption.insert(pair<string, string>("-.--", "Y"));
	encryption.insert(pair<string, string>("Z", "--.."));    decryption.insert(pair<string, string>("--..", "Z"));
	encryption.insert(pair<string, string>("_", "..--"));   decryption.insert(pair<string, string>("..--", "_"));
	encryption.insert(pair<string, string>(".", "---."));  decryption.insert(pair<string, string>("---.", "."));
	encryption.insert(pair<string, string>(",", ".-.-"));    decryption.insert(pair<string, string>(".-.-", ","));
	encryption.insert(pair<string, string>("?", "----"));    decryption.insert(pair<string, string>("----", "?"));
	
	int numberOfTestCases;
	cin >> numberOfTestCases;
	// Eliminate the return character
	getchar();
	string line;
	for (int k = 1; k <= numberOfTestCases; k++) {
		getline(cin, line);
		string multilatingMorseCode;
		string numberString;
		char number[2] = {0};
		for (int i = 0; i < line.size(); i++) {
			string key;
			key.insert(key.begin(), line[i]);
			multilatingMorseCode.append(encryption[key]);
			sprintf(number, "%d", encryption[key].size());
			numberString.append(number);			
		}

		string decryptionString;
		int startIndex = 0;
		for (int i = numberString.size() - 1; i >= 0; i--) {
			int length = numberString[i] - '0';
			string key = multilatingMorseCode.substr(startIndex, length);
			decryptionString.append(decryption[key]);
			startIndex += length;
		}
		cout << k << ": " << decryptionString << endl;
	}
	return 0;
}